package com.example;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author lv
 * @date 2021/5/16 11:31
 */

@RestController
@SpringBootApplication
public class ShardingsphereApplication {
    @Autowired
    private JdbcTemplate jdbcTemplate;

    public static void main(String[] args) {
        SpringApplication.run(ShardingsphereApplication.class);
    }
    /**
     * @Description: 获取用户列表
     */
    @GetMapping("list-user")
    public Object listUser() {
        jdbcTemplate.update("INSERT INTO `tab_user` ( `name`, `sex`, `age`, `create_time`, `update_time`, `status`)\n" +
                "VALUES\n" +
                "\t('爸爸','男',29,'2019-10-08 20:11:43','2019-10-08 20:11:43',0)");
        List list = jdbcTemplate.query("select * from tab_user limit 4", new RowMapper<Map>() {
            @Override
            public Map mapRow(ResultSet rs, int rowNum) throws SQLException {
                Map<String,Integer> row = new HashMap();
                System.out.println(rs.getInt("id"));
                row.put("id",rs.getInt("id"));
                return row;
            }
        });
        return list;
    }
}
